'use strict';

module.exports = (secret) => {
    return async function jwtErr(ctx, next) {
        const token = ctx.request.header.authorization
        let decode
        if (token != null && token) {
            try {
                decode = ctx.app.jwt.verify(token, secret)
                await next()
            } catch (error) {
                console.log('error',error);
                ctx.status = 200
                ctx.body = {
                    token: 'token过期',
                    code: 401
                }
                return
            }
        } else {
            ctx.status = 200
            ctx.body = {
                token: 'token不存在',
                code: 401
            }
        }
    }
}